package cn.mickey.exchange.service;

import cn.mickey.exchange.domain.model.AdminModel;
import cn.mickey.exchange.mapper.AdminMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class AdminService extends ServiceImpl<AdminMapper, AdminModel> {

    /**
     * 管理员登录
     * @param accountNumber
     * @return
     */
    public AdminModel login(String accountNumber) {
        AdminModel dbAdmin = baseMapper.selectOne(new LambdaQueryWrapper<AdminModel>()
                .eq(AdminModel::getAccountNumber, accountNumber));
        return dbAdmin;
    }

    /**
     * 分页获取管理员信息
     * @param page
     * @param num
     * @return
     */
    public Page getAdminList(int page, int num) {
        LambdaQueryWrapper<AdminModel> lqw = new LambdaQueryWrapper<AdminModel>()
                .select(AdminModel::getAccountNumber, AdminModel::getAdminName);
        return baseMapper.selectPage(new Page(page,num), lqw);
    }

    /**
     * 添加管理员
     * @param adminModel
     * @return
     */
    public boolean addAdmin(AdminModel adminModel) {
        return baseMapper.insert(adminModel) ==1 ;
    }

}
